
	<!-- row -->

	<div style="overflow-y: hidden;height:100%;padding-bottom:10px;">
		<div class="row col-sm-12" style="height: 100%;"  id="map_main"></div>
			
	</div>

<script type="text/javascript">
	var polyline = null;
	var map_main =null;
	var nowEditPolyline = null;
	var marker = null;
	$(window).resize(function() {
		if(map_main == null){
			map_main = new BMap.Map("map_main",{enableMapClick:false});
			map_main.centerAndZoom("济南");
			map_main.setCurrentCity("济南");        //由于有3D图，需要设置城市哦
			map_main.enableScrollWheelZoom();
			map_main.disableDoubleClickZoom()
			var mapType2 = new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_LEFT});
			map_main.addControl(mapType2);          //左上角，默认地图控件
			var ctrl = new BMapLib.TrafficControl({
			   showPanel: false //是否显示路况提示面板
			});  
			map_main.addControl(ctrl);
			ctrl.setAnchor(BMAP_ANCHOR_BOTTOM_RIGHT);  
			map_main.setMapStyle({styleJson:[{"featureType": "poilabel","elementType": "labels","stylers": {"visibility": "off"}}]});
		}
	});
	function getData(){
		$.getJSON("//api.waitbus.com/v3/?mothed=getAllPolyline" + "&token=" + token,function(data){
			if(data.result){
				polyline = data.result;
				reloadLine();
			}
		});
	}
	getData();
	setInterval(getData,60000);
	var i;
	//获取覆盖物位置
	function alertpID(e){
		console.log(e);
		var allOverLays = map_main.getOverlays();
		if(nowEditPolyline!=null){
			for(var i = 0;i<polyline.polyline.length;i++){
				if(allOverLays[i]==nowEditPolyline){
					break;
				}
			}
			if(i<allOverLays.length){
				var points = []
				for(var j = 1;j<allOverLays[i].ia.length-1;j++){
					var lng = allOverLays[i].ia[j].lng-0.012316;
					var lat = allOverLays[i].ia[j].lat-0.006531;
					points.push(lng.toFixed(6) + ',' + lat.toFixed(6)); 
				}
				$.post('//api.waitbus.com/v3/?mothed=setPolyline' + "&token=" + token,{pID:polyline.polyline[i].pID,points:points.join("|")},function(data){
					res = JSON.parse(data);
					if(res.status.code==0){
						$.bigBox({
							title : "插入成功",
							content : "折线已经上传到服务器",
							color : "#739E73",
							timeout: 8000,
							icon : "fa fa-check",
						});
					}else{
						$.bigBox({
							title : "出现错误",
							content : res.status.msg + " [" + res.status.code + "]",
							color : "#C79121",
							timeout: 8000,
							icon : "fa fa-times fadeInLeft animated",
						});
					}
				});
			}
			map_main.removeOverlay(marker);
			nowEditPolyline.disableEditing();
		}
		if(e.target!=nowEditPolyline){
			nowEditPolyline = e.target;
			nowEditPolyline.enableEditing();
			for(var i = 0;i<polyline.polyline.length;i++){
				if(allOverLays[i]==nowEditPolyline){
					break;
				}
			}
			marker = new BMap.Marker(allOverLays[i].ia[0]);
			map_main.addOverlay(marker);
		}else{
			nowEditPolyline = null;
		}
	}
	
	function reloadLine(){
		var stationUlHtml = "";
		var points = [];
		var point = null;
		var marker = null;
		var label = null;
		var myIcon = new BMap.Icon("http://api0.map.bdimg.com/images/stop_icon.png", new BMap.Size(11,11));
		if(map_main!=null){
			map_main.clearOverlays();
			/*for(var i=0;i<polyline.stations.length;i++){
				point = new BMap.Point(lineInfo.lStation[i].sLng + 0.012316,lineInfo.lStation[i].sLat + 0.006531);
				marker = new BMap.Marker(point,{icon:myIcon});
				map_main.addOverlay(marker);
				points.push(point);
			}*/
			var sy = new BMap.Symbol(BMap_Symbol_SHAPE_BACKWARD_OPEN_ARROW, {
				scale: 0.6,//图标缩放大小
				strokeColor:'#fff',//设置矢量图标的线填充颜色
				strokeWeight: '2',//设置线宽
			});
			var icons = new BMap.IconSequence(sy, '10', '30');
			for(var i=0;i<polyline.polyline.length;i++){
				var polylinepoints = []
				var polylinestring = polyline.polyline[i].pPoints + "";
				tmp = polylinestring.split("|");
				for(var j =0;j<tmp.length;j++){
					var temp = tmp[j].split(",");
					if(temp.length==2){
						polylinepoints.push(new BMap.Point(parseFloat(temp[0]) + 0.012316,parseFloat(temp[1]) + 0.006531));
					}
				}
				var color = "#5298ff";
				var Opacity = 0.3;
				if(polyline.polyline[i].pBusCount>10){
					Opacity = 0.7;
				}else if(polyline.polyline[i].pBusCount>5){
					Opacity = 0.6;
				}else if(polyline.polyline[i].pBusCount>1){
					Opacity = 0.5;
				}else{
					Opacity = 0.2;
				}
				if(polyline.polyline[i].pVelocity<0||polyline.polyline[i].pVelocity>=8){
					color ="#4FD17D";Opacity-=0.1;
				}else if(polyline.polyline[i].pVelocity>3&&polyline.polyline[i].pVelocity<8){
					color ="#F6C64D";Opacity+=0.2;
				}else{
					color = "#E80D0D";
					Opacity+=0.4;
				}
				var bdpolyline = new BMap.Polyline(polylinepoints, {strokeColor:color,strokeWeight:3,strokeOpacity:Opacity}); 
				map_main.addOverlay(bdpolyline);
				bdpolyline.addEventListener("click",alertpID);
			}
			//map_main.setViewport(points);
			
		}
	}

	function isIE() {
		return (!!window.ActiveXObject || "ActiveXObject" in window);
	}

	var pagedestroy = function(){
		map_main =null;
		map_addStation = null;
		searchTime = 0;
	}
	
	Array.prototype.insert = function (index, item) {
		this.splice(index, 0, item);
	};

	function sleep(numberMillis) {
		var now = new Date();
		var exitTime = now.getTime() + numberMillis;
		while (true) {
			now = new Date();
			if (now.getTime() > exitTime)
				return;
		}
	}
	$(window).resize();

</script>




